﻿@using BBICMS.Infrastructure
@model BBICMS.Model.ViewModel.Back.UsersVM
@{
    ViewBag.Title = "帐号管理";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}

@section leftNav{
    @Html.Partial("_NavForSecurity")
}

<div class="toolbar">
    <a href="#" class="showmenu"><i class="glyphicon glyphicon-th-list"></i></a>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index","Home")"><i class="glyphicon glyphicon-home"></i> 控制面板</a></li>
        <li>安全</li>
        <li class="active">@ViewBag.Title</li>
    </ol>
</div>
<div class="main-content">

    <div class="panel panel-default">
        <div class="panel-heading">
            <i class="glyphicon glyphicon-file"></i> @ViewBag.Title
        </div>
        <div class="panel-body text-right">
            <a class="btn btn-primary" href="@Url.Action("AddUser")"><i class="glyphicon glyphicon-plus"></i> 添加帐号</a>
        </div>
        <table class="table table-hover table-striped">
            <thead>
                <tr>
                    <th>
                        用户名
                    </th>
                    <th>
                        创建日期
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var user in Model.Users)
                {
                    <tr class="first">
                        <td>
                            @user.UserName
                        </td>
                        <td>
                            @if (user.Profile != null)
                            {
                                @user.Profile.CreateDate
                            }
                        </td>
                        <td>
                            @*<a href="Business/EditBusiness/@user.UserName" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i></a>*@
                            <a href="Security/DeleteUser/@user.UserId" data-bb="confirm" class="btn btn-xs btn-danger delete-user"><i class="glyphicon glyphicon-trash"></i></a>
                        </td>
                    </tr>
                }

            </tbody>

        </table>

        <div class="panel-footer">
            <ul class="pagination">
                @Html.PageLinks(Model.PagingInfo, x => Url.Action("Index", new { Page = x }))
            </ul>
        </div>

    </div>

</div>
<!-- end main container -->
@section footer {
<script src="~/Content/Admin/js/lib/bootbox.js"></script>
    <script>

        $(function () {
           
            //当前菜单;
               
            $('.mainmenu>li:nth(3)').addClass('nav-open').find('.submenu>li:nth(0)>a').addClass('active');

            bootbox.setDefaults({
                locale: 'zh_CN'
            });
            //删除数据
            $('.delete-user').click(function (e) {
                e.preventDefault();
                toastr.options = {
                    "positionClass": "toast-bottom-full-width"
                }

                var url = $(this).attr('href');
                var that = $(this);

                bootbox.confirm("您确定要删除此帐号吗？", function (result) {
                    if (result) {
                                              
                         console.log(url);
                        /*DELETE*/
                        $.ajax({
                            url: url,
                            dataType: "json",
                            type: "DELETE",
                            contentType: 'application/json; charset=utf-8',
                            data: JSON.stringify({}),
                            async: true,
                            processData: false,
                            cache: false,
                            success: function (data) {
                                if (data) {
                                    toastr.success('帐号已删除成功！', '删除帐号');
                                    that.closest('tr').remove();
                                } else {
                                    toastr.error('帐号删除失败！', '删除帐号');
                                }
                            },
                            error: function (xhr) {
                                toastr.error('帐号删除失败！', '删除帐号');
                            }
                        });

                        debugger;

                    }
                });

               
            })

        });
    </script>

}
